package com.gs.weather.controller;

import com.gs.weather.entity.DisasterInfo;
import com.gs.weather.entity.DisasterProcess;
import com.gs.weather.service.DisasterInfoService;
import com.gs.weather.service.DisasterProcessService;
import com.gs.weather.service.XsAreaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: Legolas
 * Date: 2017/9/27 0027
 */
@Controller
@RequestMapping(value = "process")
public class DisasterProcessController {

    @Autowired
    XsAreaService areaService;
    @Autowired
    DisasterProcessService processService;
    @Autowired
    DisasterInfoService infoService;

    //获取所有街镇名
    @RequestMapping(value = "getAreaName")
    @ResponseBody
    public List<String> getAreaNames() {
        return areaService.getXsAreaName();
    }

    //添加灾情过程
    @RequestMapping(value = "addProcess")
    public void getProcess(DisasterProcess process) {
        processService.addProcess(process);
    }

    //更新灾情过程
    @RequestMapping(value = "updateProcess")
    public void updateProcess(DisasterProcess process) {
        processService.updateProcess(process);
    }

    /*pageHelper分页*/
    //获取灾情过程
    @RequestMapping(value = "getProcess")
    @ResponseBody
    public List<DisasterProcess> getProcess(Integer pageNum) {
        return processService.getAllProcess(pageNum).getList();
    }

    //根据街镇名查询灾情过程
    @RequestMapping(value = "getProcessByAreaName")
    @ResponseBody
    public List<DisasterProcess> getProcessByAreaName(String name, Integer pageNum) {
        return processService.getProcessByXsAreaName(name, pageNum).getList();
    }

    //根据时间查询灾情过程
    @RequestMapping(value = "getProcessByTime")
    @ResponseBody
    public List<DisasterProcess> getProcessByTime(String time, Integer pageNum) {
        return processService.getProcessByTime(time, pageNum).getList();
    }

    //根据时间和街镇名查询灾情过程
    @RequestMapping(value = "getProcessByAreaNameAndTime")
    @ResponseBody
    public List<DisasterProcess> getProcessByAreaNameAndTime(String name, String time, Integer pageNum) {
        return processService.getProcessByXsAreaNameAndTime(name, time, pageNum).getList();
    }

    //根据id查看灾情过程（包含该过程的所有灾情信息）
    @RequestMapping(value = "getProcessById")
    @ResponseBody
    public DisasterProcess getProcessById(long id) {
        return processService.getProcessById(id);
    }

    //删除灾情过程
    @RequestMapping(value = "deleteProcess")
    public void deleteProcess(long id) {
        processService.deleteProcess(id);
    }

    //添加灾情信息
    @RequestMapping(value = "addInfo")
    public void addInfo(DisasterInfo info) {
        infoService.addInfo(info);
    }

    //更新灾情信息
    @RequestMapping(value = "updateInfo")
    public void updateInfo(DisasterInfo info) {
        infoService.updateInfo(info);
    }

    //根据街镇名查询灾情信息
    @RequestMapping(value = "getInfoByAreaName")
    @ResponseBody
    public List<DisasterInfo> getInfoByAreaName(String name, Integer pageNum) {
        return infoService.getInfoByXsAreaName(name, pageNum).getList();
    }

    //删除灾情信息
    @RequestMapping(value = "deleteInfo")
    public void deleteInfo(long id) {
        infoService.deleteInfo(id);
    }

}
